<template>
	<view class="content">
		
		<!-- <view class="whiteBox"> -->
			<view class="err" >
				<view v-if="isArr">{{wrongMsg}}</view>
			</view>
		<!-- </view> -->
        <form @submit="formSubmit" @reset="formReset" class="uni-form">
        	<view class="section">
        		<input name="input" placeholder="手机号" v-model="userPhone" maxlength="11"/>
        	</view>
        	<view class="section">
        		<input name="input" type="password" placeholder="密码" v-model="userPas"/>
        	</view>
        	<view class="btn-area">
        		<button type="primary" @click="loginIn">登录</button>
        	</view>
        </form>
	</view>
</template>

<script>
	//引入公共文件
	let common = require('../../common/common.js');
	export default {
		data() {
			return {
				userPhone:'',//手机号
				userPas:'',//密码
				wrongMsg:'1233545646',//错误信息提示
				isArr:false, //是否显示错误信息
			}
		},
		methods: {
			// 登录
			loginIn(){
				this.isArr = false;
				this.wrongMsg = '';
				// 验证手机号和密码是否按要求输入
				if(!this.userPhone || !this.userPas){
					this.isArr = true;
					this.wrongMsg = '请输入手机号或密码';
				}else if(common.phoneVertify(this.userPhone).type){
					this.isArr = true;
					this.wrongMsg = common.phoneVertify(this.userPhone).error;
				}else if(!common.pasVertify(this.userPas).type){
					this.isArr = true;
					this.wrongMsg = common.pasVertify(this.userPas).error;
				}else{
					uni.request({
						url: this.$BaseUrl + "pLogin",
						method: 'POST',
						data: {
							phone: this.userPhone,
							password: this.userPas,
						},
						success: (res) => {
							if(res.data.code == 0){
								uni.setStorageSync('userInfo', JSON.parse(JSON.stringify(res.data.data)));
								uni.navigateTo({
									url:'/pages/home/home'
								})
							}else{
								 uni.showToast({
									icon: 'none',
									title: res.data.msg
								});
							}
						}
					});
				}
			},
		}
	}
</script>

<style>
	.content {
		height: auto;
		position: relative;
	}
	.header-box{
		height: 120upx;
	}
	.err{
		width:100%;
		height: 100upx;
	}
	.err view{
		text-align: center;
		font-size: 30upx;
		line-height: 90upx;
		color: red;
	}
	.whiteBox{
		width:100%;
		height: 100upx;
	}
	.uni-form input{
		width:91.47%;
		height: 100upx;
		margin: auto;
		font-size: 28upx;
		line-height: 100upx;
		border-bottom:1px solid #ddd ;
		padding-left: 30upx;
		box-sizing: border-box;
	}
	.btn-area{
		width:91.47%;
		margin:90upx auto;
		background-color: #02A8F4;
	}
	.title {
		font-size: 36upx;
		color: #8f8f94;
	}
</style>
